package cn.xuewenbao.ucenter.controller;


import cn.xuewenbao.ucenter.entity.vo.FollowVo;
import cn.xuewenbao.ucenter.service.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 关注表 前端控制器
 * </p>
 *
 * @author mafayu
 * @since 2021-04-19
 */
@Api(tags = "关注表")
@RestController
@RequestMapping("/ucenter/follow")
public class FollowController {

    @Autowired
    private FollowService followService;

    //获取关注列表或粉丝列表
    @ApiOperation(value = "获取关注列表或粉丝列表")
    @PostMapping("/followInfo")
    public Result<Object> followInfo(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String type = map.get("type");
        return followService.getFollowInfo(userId, type);
    }

    //关注某人
    @ApiOperation(value = "关注某人")
    @PostMapping("/followOne")
    public Result<?> followOne(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String followedId = map.get("followedId");
        Result<?> result = followService.followOne(userId, followedId);
        return result;
    }

    //取消关注某人
    @ApiOperation(value = "取消关注某人")
    @PostMapping("/unfollowOne")
    public Result<?> unfollowOne(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String followedId = map.get("followedId");
        Result<?> result = followService.unfollowOne(userId, followedId);
        return result;
    }

    //是否关注某人
    @ApiOperation(value = "是否关注某人")
    @PostMapping("/hasFollowOne")
    public Result<?> hasFollowOne(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String targetUserId = map.get("targetUserId");
        Result<?> result = followService.hasFollowOne(userId, targetUserId);
        return result;
    }

    //得到该作者的昨天的粉丝量
    @ApiOperation("得到该作者的昨天的粉丝量")
    @GetMapping("getLastFanCount/{userId}")
    public Result<Map<String, Long>> getLastFanCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = followService.getLastFanCount(userId);
        return result;
    }

    //得到该作者的一周的粉丝量
    @ApiOperation("得到该作者的一周的粉丝量")
    @GetMapping("getWeekFanCount/{userId}")
    public Result<Map<String, Long>> getWeekFanCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = followService.getWeekFanCount(userId);
        return result;
    }

    //得到该作者的一月的粉丝量
    @ApiOperation("得到该作者的一月的粉丝量")
    @GetMapping("getMonthFanCount/{userId}")
    public Result<Map<String, Long>> getMonthFanCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = followService.getMonthFanCount(userId);
        return result;
    }

    //得到该作者的总粉丝量
    @ApiOperation("得到该作者的总粉丝量")
    @GetMapping("getTotalFanCount/{userId}")
    public Result<Integer> getTotalFanCount(@PathVariable String userId){
        Result<Integer> result = followService.getTotalFanCount(userId);
        return result;
    }
}

